module.exports = class extends think.Controller {
  async __before() {
    const isLogin = await this.islogion();
    if (!isLogin) {
      const url = this.ctx.url;
      if (!url.match(/\/common\/login/)) {
        return this.redirect('/common/login');
      }
    }
    // 登录
    this.user = await this.session('userInfo');
    this.assign('url', this.ctx.url.replace('.html', ''));
    this.assign('userinfo', this.user);
  }

  async islogion() {
    const user = await this.session('userInfo');
    const res = think.isEmpty(user) ? false : user.id;
    return res;
  }
};
